package com.freshcity.page.home
{
	import com.freshcity.common.ReadMsgWin;
	import com.freshcity.component.container.Component;
	import com.freshcity.core.MainScene;
	import com.freshcity.core.OpCodes;
	import com.freshcity.manager.EffectManager;
	import com.freshcity.manager.LayerManager;
	import com.freshcity.utils.StringUtil;
	import com.greensock.TweenLite;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.BitmapFilterType;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public class ReadMessage extends Component
	{
		private var back:ReadMsgWin;
		private var _data:Array;
		private var _currentMsg:*;
		private var userTxt:TextField;

		public function ReadMessage()
		{
			super(null, 0, 0);
			this.setSize(200,100);
			back.confirmBtn.addEventListener(MouseEvent.CLICK, onSubmit);
			//back.filters = [getDropShadowFilter()];
		}
		
		private function getDropShadowFilter():DropShadowFilter
		{
			var loc1:*=0;
			var loc2:*=90;
			var loc3:*=0.6;
			var loc4:*=12;
			var loc5:*=4;
			var loc6:*=1;
			var loc7:*=1;
			var loc8:*=false;
			var loc9:*=false;
			var loc10:*=BitmapFilterQuality.LOW;
			return new DropShadowFilter(loc6, loc2, loc1, loc3, loc4, loc5, loc7, loc10, loc8, loc9);
		}		

		override protected function addChildren():void
		{
			super.addChildren();
			back=new ReadMsgWin();
			addChild(back);

		}

		private function onIgnore(event:Event):void
		{
			showContent();
		}

		
		protected function onSubmit(event:Event):void
		{
			MainScene.writeMsg.uid=String(_currentMsg.from_user);
			MainScene.writeMsg.isReply=true;
			MainScene.writeMsg.callback=showContent;
			MainScene.writeMsg.onShow();
		}

		override public function draw():void
		{
			super.draw();
			
			userTxt = new TextField();
			userTxt.autoSize = TextFieldAutoSize.LEFT;
			userTxt.multiline = true;
			userTxt.styleSheet = StringUtil.style;
			userTxt.addEventListener(TextEvent.LINK, main.onAboutUser,false,0,true);
			userTxt.x=140; 
			userTxt.y=5;
			addChild(userTxt);
			
			var loc2:TextField=StringUtil.addHyLink("忽略", "", onIgnore);
			loc2.x=120;
			loc2.y=78;
			addChild(loc2);
		}

		public function get data():Array
		{
			return _data;
		}

		public function set data(value:Array):void
		{
			_data=value;
			this.x = (main.stage.stageWidth-this.width)-2;
			this.y = (main.stage.stageHeight-this.height)-5;
			//EffectManager.addUIMask([], 0);
			LayerManager.msgTipLayer.addChild(this);

			showContent();
		}

		private function showContent():void
		{
			_currentMsg = _data.shift();
			if (_currentMsg)
			{
				userTxt.htmlText = "".concat("<a href='event:",_currentMsg.from_user,"'>","个人资料","</a>");
				back.from.text = "用户" + _currentMsg.from_user;
				back.words.text=_currentMsg.content;
				TweenLite.from(this,0.5,{alpha:0,y:"+50"});
			}
			else
			{
				this.destroy();
			}
		}

	}
}